import java.util.Observable;
import java.util.*;

public class Time extends Observable{

	private int currentTime=0;
	private int endOfTime = 100;
	long millis = System.currentTimeMillis();
	private List<VehicleQueue> tempList = new ArrayList<VehicleQueue>();
	
	private static Time instance;
	
	public Time(){
	}
	
	public synchronized static Time getInstance(){
		if(instance==null){
			instance=new Time();
		}
		return instance;
	}
	
	public void initEndOfTime(int numberOfSeconds){
		endOfTime=numberOfSeconds;
	}
	
	public int getCurrentTime(){
		return currentTime;
	}
	
	public void run(){
		if(currentTime<endOfTime){
		long millisToWait=1000;
		while((System.currentTimeMillis()-millis)<millisToWait){	
		}
		currentTime++;
		notifyObservers();
		run();
		}
	}
	
	public void notifyObservers(){
		for(VehicleQueue it : tempList){
			it.update(null, currentTime);
		}
	}
	
	
}
